package leetcode.primary;

public class T29 {
    public int divide(int dividend, int divisor) {
        int opr;
        if(dividend==0){
            return 0;
        }
        if(dividend<0 || divisor<0){
            if(dividend<0 && divisor>0){
                opr = -1;
                dividend = ~dividend+1;

            }else if(dividend>0 && divisor<0){
                opr = -1;
                divisor = ~divisor+1;
            }else{
                opr = 1;
                dividend = ~dividend+1;
                divisor = ~divisor+1;
            }
        }else{
            opr = 1;
        }
        int count=0;
        while(dividend-divisor>0){
            dividend -= divisor;
            count++;
        }
        System.out.println(opr);
        if(count>Integer.MAX_VALUE || (~count)+1<Integer.MIN_VALUE){
            return Integer.MAX_VALUE;
        }
        if(opr==1){
            return count;
        }else{
            return (~count)+1;
        }
    }
    public static void main(String[] args){
        T29 cc = new T29();
        int x = cc.divide(-2147483648,-1);
        System.out.println(x);
    }
}
